 package com.oanda.blackberry.view;
 
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.FontFamily;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.LabelField;
 
 public class HeaderField extends LabelField
 {
   private String label = "";
   private String time;
   private int backgroundColorFocused = 8421504;
   private int backgroundColorUnfocused = 11119017;
 
   private int textColorFocused = 16776960;
   private int textColorUnfocused = 32768;
 
   private int fontColorLeft = 139;
   private int fontColorRight = 139;
   private int fontColorCenter = 139;
 
   int horizontalPadding = 2;
   int verticalPadding = 2;
   Font font;
   int fontHight = 20;
   String left;
   String center;
   String right;
   int width;
   int minWidth = 300;
 
   public HeaderField(String left, String center, String right) {
     this(4503599627370496L, left, center, right);
   }
 
   public HeaderField(long style, String left, String center, String right) {
     super("", style);
     this.left = left;
     this.right = right;
     this.center = center;
 
     FontFamily ff = null;
     try {
       ff = FontFamily.forName("BBAlpha Sans");
       this.font = ff.getFont(0, this.fontHight);
     } catch (ClassNotFoundException n) {
       this.font = Font.getDefault().derive(0, this.fontHight);
     }
 
     this.width = getWidth();
   }
 
   public void setWidth(int w) {
     this.width = w;
   }
 
   protected void layout(int maxWidth, int maxHeight) {
     if (this.width < this.minWidth) {
       this.width = this.minWidth;
     }
     setExtent(this.width, 2 * this.verticalPadding + this.fontHight);
   }
 
   protected void paint(Graphics graphics)
   {
     graphics.setColor(isFocus() ? this.backgroundColorFocused : this.backgroundColorUnfocused);
     graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
 
     graphics.setColor(isFocus() ? this.textColorFocused : this.textColorUnfocused);
 
     int fontWidth = getFont().getAdvance(this.label + " " + this.time);
 
     if (this.left != null) {
       graphics.setColor(this.fontColorLeft);
       graphics.drawText(this.left, this.horizontalPadding, this.verticalPadding, 0x30 | 0x6, this.width - 2 * this.horizontalPadding);
     }
 
     if (this.center != null) {
       graphics.setColor(this.fontColorCenter);
       graphics.drawText(this.center, this.horizontalPadding, this.verticalPadding, 0x30 | 0x4, this.width - 2 * this.horizontalPadding);
     }
 
     if (this.right != null) {
       graphics.setColor(this.fontColorRight);
       graphics.drawText(this.right, this.horizontalPadding, this.verticalPadding, 0x30 | 0x5, this.width - 2 * this.horizontalPadding);
     }
   }
 
   public void setBGColor(int color)
   {
     this.backgroundColorUnfocused = color;
   }
 
   public void setFontColorLeft(int color) {
     this.fontColorLeft = color;
   }
 
   public void setFontColorRight(int color) {
     this.fontColorRight = color;
   }
 
   public void setFontColorCenter(int color) {
     this.fontColorCenter = color;
   }
 
   public boolean isFocusable() {
     return false;
   }
 
   protected void drawFocus(Graphics graphics, boolean on)
   {
   }
 
   protected void onFocus(int direction) {
     super.onFocus(direction);
     invalidate();
   }
 
   protected void onUnfocus() {
     super.onUnfocus();
     invalidate();
   }
}

